<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>CKEDITOR</title>
	<link rel="stylesheet" type="text/css" href="../test.css" />
	<script type="text/javascript" src="../../ckeditor.js"></script>
	<script type="text/javascript" src="../test.js"></script>
	<script type="text/javascript">
	//<![CDATA[
	// Clean up all instances been created on the page.
	function removeAllInstances()
	{
		var allInstances = CKEDITOR.instances;
		for( var i in allInstances )
		{
			CKEDITOR.remove(  allInstances[ i ] );
		}
	}

	CKEDITOR.test.addTestCase( (function()
{
	// Local reference to the "assert" object.
	var assert = CKEDITOR.test.assert;

	return {
		test_replaceClass : function()
		{
			// Asserts the default value.
			assert.areSame( 'ckeditor', CKEDITOR.replaceClass );
		},

		test_replaceByClassEnabled : function()
		{
			// Asserts the default value.
			assert.isTrue( CKEDITOR.replaceByClassEnabled );
		},

		test_replaceId : function()
		{
			CKEDITOR.replace( 'editor1' );
			assert.isObject( CKEDITOR.instances.editor1, 'editor instance not found' );
			assert.areSame( 'editor1', CKEDITOR.instances.editor1.name, 'instance name doesn\'t match' );
			assert.areSame( document.getElementById( 'editor1' ), CKEDITOR.instances.editor1.element.$, 'instance element doesn\'t match' );
		},

		test_replaceName : function()
		{
			CKEDITOR.replace( 'editor2' );
			assert.isObject( CKEDITOR.instances.editor2, 'editor instance not found' );
			assert.areSame( 'editor2', CKEDITOR.instances.editor2.name, 'instance name doesn\'t match' );
			assert.areSame( document.getElementsByName( 'editor2' )[0], CKEDITOR.instances.editor2.element.$, 'instance element doesn\'t match' );
		},

		test_replaceElement : function()
		{
			CKEDITOR.replace( document.getElementById( 'editor5' ) );
			assert.isObject( CKEDITOR.instances.editor5, 'editor instance not found' );
			assert.areSame( 'editor5', CKEDITOR.instances.editor5.name, 'instance name doesn\'t match' );
			assert.areSame( document.getElementById( 'editor5' ), CKEDITOR.instances.editor5.element.$, 'instance element doesn\'t match' );
		},


		test_replaceError : function()
		{
			try
			{
				CKEDITOR.replace( 'error' );
			}
			catch ( e )
			{
				assert.areSame( '[CKEDITOR.editor.replace] The element with id or name "error" was not found.', e );
			}
		},

		test_replaceAll_Class : function()
		{
			CKEDITOR.replaceAll( 'myclass' );

			assert.isObject( CKEDITOR.instances.editor3, 'editor3 instance not found' );
			assert.areSame( 'editor3', CKEDITOR.instances.editor3.name, 'editor3 instance name doesn\'t match' );
			assert.areSame( document.getElementById( 'editor3' ), CKEDITOR.instances.editor3.element.$, 'editor3 instance element doesn\'t match' );

			assert.isObject( CKEDITOR.instances.editor4, 'editor4 instance not found' );
			assert.areSame( 'editor4', CKEDITOR.instances.editor4.name, 'editor4 instance name doesn\'t match' );
			assert.areSame( document.getElementsByName( 'editor4' )[0], CKEDITOR.instances.editor4.element.$, 'editor4 instance element doesn\'t match' );

			assert.isUndefined( CKEDITOR.instances.editor6, 'editor6 should be undefined' );
			assert.isUndefined( CKEDITOR.instances.editor7, 'editor7 should be undefined' );
			assert.isUndefined( CKEDITOR.instances.editor8, 'editor8 should be undefined' );
			assert.isUndefined( CKEDITOR.instances.editor8, 'editor9 should be undefined' );
		},

		test_replaceAll_Function : function()
		{
			CKEDITOR.replaceAll( function( textarea )
				{
					return ( textarea.id != 'editor6' && textarea.id != 'editor8' );
				} );

			assert.isObject( CKEDITOR.instances.editor7, 'editor7 instance not found' );
			assert.areSame( 'editor7', CKEDITOR.instances.editor7.name, 'editor7 instance name doesn\'t match' );
			assert.areSame( document.getElementById( 'editor7' ), CKEDITOR.instances.editor7.element.$, 'editor7 instance element doesn\'t match' );

			assert.isObject( CKEDITOR.instances.editor9, 'editor9 instance not found' );
			assert.areSame( 'editor9', CKEDITOR.instances.editor9.name, 'editor9 instance name doesn\'t match' );
			assert.areSame( document.getElementById( 'editor9' ), CKEDITOR.instances.editor9.element.$, 'editor9 instance element doesn\'t match' );

			assert.isUndefined( CKEDITOR.instances.editor6, 'editor6 should be undefined' );
			assert.isUndefined( CKEDITOR.instances.editor8, 'editor8 should be undefined' );
		},

		test_replaceAll : function()
		{
			CKEDITOR.replaceAll();

			assert.isObject( CKEDITOR.instances.editor6, 'editor6 instance not found' );
			assert.areSame( 'editor6', CKEDITOR.instances.editor6.name, 'editor6 instance name doesn\'t match' );
			assert.areSame( document.getElementById( 'editor6' ), CKEDITOR.instances.editor6.element.$, 'editor6 instance element doesn\'t match' );

			assert.isObject( CKEDITOR.instances.editor8, 'editor8 editor instance not found' );
			assert.areSame( 'editor8', CKEDITOR.instances.editor8.name, 'editor8 instance name doesn\'t match' );
			assert.areSame( document.getElementById( 'editor8' ), CKEDITOR.instances.editor8.element.$, 'editor8 instance element doesn\'t match' );
		},

		test_add : function()
		{
			var textarea = CKEDITOR.dom.element.createFromHtml( '<textarea id="test_add">&lt;p&gt;test_add&lt;/p&gt;<\/textarea>' );
			textarea.appendTo( new CKEDITOR.dom.element( document.body ) );

			var editor = new CKEDITOR.editor( {}, textarea, CKEDITOR.ELEMENT_MODE_REPLACE );

			CKEDITOR.add( editor );

			assert.areSame( editor, CKEDITOR.instances.test_add );
		},

		setUp : function()
		{
			removeAllInstances();
		},

		name : document.title
	};
})() );

	//]]>
	</script>
</head>
<body>
	<textarea id="editor1" cols="80" rows="10"></textarea>
	<textarea name="editor2" cols="80" rows="10"></textarea>
	<textarea id="editor3" name="editor3" class="myclass" cols="80" rows="10"></textarea>
	<textarea name="editor4" class="myclass" cols="80" rows="10"></textarea>
	<textarea id="editor5" cols="80" rows="10"></textarea>
	<textarea id="editor6" cols="80" rows="10"></textarea>
	<textarea id="editor7" cols="80" rows="10"></textarea>
	<textarea id="editor8" cols="80" rows="10"></textarea>
	<textarea id="editor9" cols="80" rows="10"></textarea>
</body>
</html>
